home *** CD-ROM | disk | FTP | other *** search
/ Game Programming in C++ - Start to Finish / GameProgrammingS.iso / Peon / PeonSDK-Win32-1.0.0.exe / {app} / PeonMain / include / InputEngine.h < prev    next >
Encoding:
C/C++ Source or Header  |  2005-11-18  |  3.8 KB  |  129 lines

  1.  
  2. #ifndef __INPUTENGINE_H_
  3. #define __INPUTENGINE_H_
  4. /*
  5. Peon - Win32 Games Programming Library
  6. Copyright (C) 2002-2005 Erik Yuzwa
  7.  
  8. This library is free software; you can redistribute it and/or
  9. modify it under the terms of the GNU Library General Public
  10. License as published by the Free Software Foundation; either
  11. version 2 of the License, or (at your option) any later version.
  12.  
  13. This library is distributed in the hope that it will be useful,
  14. but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  16. Library General Public License for more details.
  17.  
  18. You should have received a copy of the GNU Library General Public
  19. License along with this library; if not, write to the Free
  20. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  21.  
  22. Erik Yuzwa
  23. peon AT wazooinc DOT com
  24. */
  25.  
  26. #include "ISingleton.h"
  27.  
  28. #define JOYSTICK_DEAD_ZONE 32768.0f
  29.  
  30.  
  31. namespace peon
  32. {
  33.     /**
  34.     * This object keeps an eye on the input received by SDL
  35.     *
  36.     * This singleton object is a manager "of sorts" for the input 
  37.     * devices available on the system. 
  38.     */
  39.     class PEONMAIN_API InputEngine : public ISingleton<InputEngine>
  40.     {
  41.     protected:
  42.         /** handle to the joystick */
  43.         SDL_Joystick*        m_pJoystick;
  44.  
  45.         /** is there a joystick connected? */
  46.         bool                m_bJoystickConnected;
  47.  
  48.     public:
  49.         /**
  50.         * Constructor
  51.         */
  52.         InputEngine();
  53.  
  54.         /**
  55.         * Destructor
  56.         */
  57.         ~InputEngine();
  58.  
  59.         /** Override standard Singleton retrieval.
  60.         @remarks
  61.         Why do we do this? Well, it's because the Singleton
  62.         implementation is in a .h file, which means it gets compiled
  63.         into anybody who includes it. This is needed for the
  64.         Singleton template to work, but we actually only want it
  65.         compiled into the implementation of the class based on the
  66.         Singleton, not all of them. If we don't change this, we get
  67.         link errors when trying to use the Singleton-based class from
  68.         an outside dll.
  69.         @par
  70.         This method just delegates to the template version anyway,
  71.         but the implementation stays in this single compilation unit,
  72.         preventing link errors.
  73.         */
  74.         static InputEngine& getSingleton(void);
  75.         /** Override standard Singleton retrieval.
  76.         @remarks
  77.         Why do we do this? Well, it's because the Singleton
  78.         implementation is in a .h file, which means it gets compiled
  79.         into anybody who includes it. This is needed for the
  80.         Singleton template to work, but we actually only want it
  81.         compiled into the implementation of the class based on the
  82.         Singleton, not all of them. If we don't change this, we get
  83.         link errors when trying to use the Singleton-based class from
  84.         an outside dll.
  85.         @par
  86.         This method just delegates to the template version anyway,
  87.         but the implementation stays in this single compilation unit,
  88.         preventing link errors.
  89.         */
  90.         static InputEngine* getSingletonPtr(void);
  91.  
  92.  
  93.         /**
  94.         * This method loads up and configures our input devices. SDL 
  95.         * will automagically create our handles to the keyboard and
  96.         * mouse device, so we're really only talking about initializing
  97.         * a handle to the joystick.
  98.         *
  99.         * I always return true, as I feel the game should not bail just
  100.         * because the joystick was not found/inited properly. Feel free
  101.         * to modify depending upon your game's needs.
  102.         *
  103.         * @param pConfig - a valid IniConfigReader instance
  104.         * @return bool - always true
  105.         */
  106.         bool loadEngine( IniConfigReader* pConfig );
  107.  
  108.         /**
  109.         * This method just unloads and frees any allocated input devices
  110.         */
  111.         void unloadEngine();
  112.  
  113.         /**
  114.         * This method returns the current X axis of the joystick
  115.         * @return Sint16 - value of our x axis
  116.         */
  117.         Sint16 getJoyXAxis();
  118.  
  119.         /**
  120.         * This method returns the current Y axis of the joystick
  121.         * @return Sint16 - value of our y axis
  122.         */
  123.         Sint16 getJoyYAxis();
  124.  
  125.     };
  126. }
  127.  
  128. #endif
  129.